append([], L, L).
append([X|XS], YS, [X|ZS]) :- append(XS, YS, ZS).

primeros([_], []).
primeros([X|[Y|XS]], [X|YS]) :- primeros([Y|XS], YS).

cabeza([X|_], X).

cola([_|XS], XS).

%rotar(+L, +N, -R)
rotar(L, 0, L).
rotar(L, N, YS) :- N > 0, Nm1 is N - 1, rotar(L, Nm1, ZS), last(ZS, Ultimo), primeros(ZS, TodosMenosUltimo), append([Ultimo], TodosMenosUltimo, YS).
rotar(L, N, YS) :- N < 0, Nm1 is N + 1, rotar(L, Nm1, ZS), cabeza(ZS, Cab), cola(ZS, Cola), append(Cola, [Cab], YS).